﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="User.aspx.cs" Inherits="FrameWork.web.Module.IntegralMS.IntegralMS.UserSelect.User" %>

<html>
<head>
    <title>添加人员</title>
    <style>
        .menulines
        {
            cursor: pointer;
            cursor: hand;
        }
    </style>
    <script language="JavaScript">
var userlist=new Array();
<%=strUserList%>

var parent_window;
if(window.navigator.appName.toLowerCase().indexOf("netscape") > -1)
	parent_window = window.parent.opener;
else
	parent_window = parent.dialogArguments;

function click_user(user_id)
{
  TO_VAL=parent_window.document.getElementById("<% =ViewState["ToId"] %>").value;
  TO_NAME=parent_window.document.getElementById("<% =ViewState["ToName"] %>").value;
  
  targetelement=document.getElementById("USER_"+user_id);
  user_name=targetelement.getAttribute("name");

  if(TO_VAL.indexOf(","+user_id+",")>0 || TO_VAL.indexOf(user_id+",")==0)
  {
    if(TO_VAL.indexOf(user_id+",")==0)    
       parent_window.document.getElementById("<% =ViewState["ToId"] %>").value=parent_window.document.getElementById("<% =ViewState["ToId"] %>").value.replace(user_id+",","");
   
    if(TO_VAL.indexOf(","+user_id+",")>0)   
       parent_window.document.getElementById("<% =ViewState["ToId"] %>").value=parent_window.document.getElementById("<% =ViewState["ToId"] %>").value.replace(","+user_id+",",",");
     
    if(TO_NAME.indexOf(user_name+",")==0)
       parent_window.document.getElementById("<% =ViewState["ToName"] %>").value=parent_window.document.getElementById("<% =ViewState["ToName"] %>").value.replace(user_name+",","");
     
    if(TO_NAME.indexOf(","+user_name+",")>0)
       parent_window.document.getElementById("<% =ViewState["ToName"] %>").value=parent_window.document.getElementById("<% =ViewState["ToName"] %>").value.replace(","+user_name+",",",");
          
    borderize_off(targetelement);
  }
  else
  {
    parent_window.document.getElementById("<% =ViewState["ToId"] %>").value+=user_id+",";
    parent_window.document.getElementById("<% =ViewState["ToName"] %>").value+=user_name+",";
    
    borderize_on(targetelement);
  }
}

function borderize_on(targetelement)
{
 color="#003FBF";
 targetelement.style.borderColor="black";
 targetelement.style.backgroundColor=color;
 targetelement.style.color="white";
 targetelement.style.fontWeight="bold";
}

function borderize_off(targetelement)
{
  targetelement.style.backgroundColor="";
  targetelement.style.borderColor="";
  targetelement.style.color="";
  targetelement.style.fontWeight="";
}

function begin_set()
{
  TO_VAL=parent_window.document.getElementById("<% =ViewState["ToId"] %>").value;  
  for (step_i=0; step_i<userlist.length; step_i++)
  {
	 user_id=userlist[step_i];
     if(TO_VAL.indexOf(","+user_id+",")>0 || TO_VAL.indexOf(user_id+",")==0)
		borderize_on(document.getElementById("USER_"+userlist[step_i]));
  }
}

function add_all()
{
  TO_VAL=parent_window.document.getElementById("<% =ViewState["ToId"] %>").value;
  for (step_i=0; step_i<userlist.length; step_i++)
  {
    user_id=userlist[step_i];
    user_name=document.getElementById("USER_"+userlist[step_i]).getAttribute("name");

    if(TO_VAL.indexOf(","+user_id+",")<0 && TO_VAL.indexOf(user_id+",")!=0)
    {
        parent_window.document.getElementById("<% =ViewState["ToId"] %>").value+=user_id+",";
        parent_window.document.getElementById("<% =ViewState["ToName"] %>").value+=user_name+",";
        
        borderize_on(document.getElementById("USER_"+userlist[step_i]));
    }
  }
}

function del_all()
{
  for(step_i=0; step_i<userlist.length; step_i++)
  {  
	TO_VAL=parent_window.document.getElementById("<% =ViewState["ToId"] %>").value;
	TO_NAME=parent_window.document.getElementById("<% =ViewState["ToName"] %>").value;
	
    user_id=userlist[step_i];
    user_name=document.getElementById("USER_"+userlist[step_i]).getAttribute("name");
    
	if(TO_VAL.indexOf(","+user_id+",")>0 || TO_VAL.indexOf(user_id+",")==0)
	{
		if(TO_VAL.indexOf(user_id+",")==0)    
			parent_window.document.getElementById("<% =ViewState["ToId"] %>").value=parent_window.document.getElementById("<% =ViewState["ToId"] %>").value.replace(user_id+",","");
	   
		if(TO_VAL.indexOf(","+user_id+",")>0)   
			parent_window.document.getElementById("<% =ViewState["ToId"] %>").value=parent_window.document.getElementById("<% =ViewState["ToId"] %>").value.replace(","+user_id+",",",");
		  
		if(TO_NAME.indexOf(user_name+",")==0)
			parent_window.document.getElementById("<% =ViewState["ToName"] %>").value=parent_window.document.getElementById("<% =ViewState["ToName"] %>").value.replace(user_name+",","");
	     
		if(TO_NAME.indexOf(","+user_name+",")>0)
			parent_window.document.getElementById("<% =ViewState["ToName"] %>").value=parent_window.document.getElementById("<% =ViewState["ToName"] %>").value.replace(","+user_name+",",",");
	          
		borderize_off(document.getElementById("USER_"+userlist[step_i]));
	}
  }
}
    </script>
</head>
<body class="bodycolor" topmargin="1" leftmargin="0" onload="begin_set();">
    <form id="Form1" method="post" runat="server">
    <asp:Repeater ID="rptUsers" runat="server">
        <HeaderTemplate>
            <table border="1" cellspacing="0" width="100%" class="small" cellpadding="3" bordercolorlight="#000000"
                bordercolordark="#ffffff">
                <tr class="TableHeader">
                    <td colspan="2" align="center">
                        <b>
                            <% =ViewState["G_CName"] %>
                        </b>
                    </td>
                </tr>
                <tr class="TableContent">
                    <td class="menulines" onclick="javascript:add_all();" align="center">
                        全部添加
                    </td>
                </tr>
                <tr class="TableContent">
                    <td class="menulines" onclick="javascript:del_all();" align="center">
                        全部删除
                    </td>
                </tr>
        </HeaderTemplate>
        <ItemTemplate>
            <tr class="TableControl">
                <td style="cursor: pointer; cursor: hand;" id="USER_<%#DataBinder.Eval(Container.DataItem,"UserId")%>"
                    name="<%#DataBinder.Eval(Container.DataItem,"UserID")%>" align="center" onclick="javascript:click_user('<%#DataBinder.Eval(Container.DataItem,"UserId")%>');">
                    <%#DataBinder.Eval(Container.DataItem,"U_CName")%>
                </td>
            </tr>
        </ItemTemplate>
        <FooterTemplate>
            </table>
        </FooterTemplate>
    </asp:Repeater>
    <asp:Literal ID="litMessage" runat="server"></asp:Literal>
    </form>
</body>
</html>
